package dl.jf.web.action;

import java.util.ArrayList;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.util.ServletContextAware;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import dl.jf.common.model.LabelValue;
import dl.jf.service.iservice.ICommonService;

public class BaseAction extends ActionSupport implements Action, SessionAware,
		ServletRequestAware, ServletResponseAware, ServletContextAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = -24215739123901305L;
	public static Logger logger;
	
	private ActionContext context;
	public ActionContext getContext() {
		if(context == null) {
			context = ActionContext.getContext();
		}
		return context;
	}

	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected SessionMap<String, Object> session;

	public BaseAction(String className) {
		logger = Logger.getLogger(className);
//		context = ActionContext.getContext();
//		request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);  
//	    response = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE);  
//	    session = (SessionMap<String, Object>)context.getSession();
	}

	private ICommonService commonService;

	public void setCommonService(ICommonService commonService) {
		this.commonService = commonService;
	}

	protected ArrayList<LabelValue> getCodeLabelListById(int codeId) {
		return this.commonService.getCodeLabelListById(codeId);
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session = (SessionMap<String, Object>)arg0;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
		
	}

	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.response = arg0;
	}

	@Override
	public void setServletContext(ServletContext arg0) {
		// TODO Auto-generated method stub
		
	}
}
